﻿using System;
using System.Web;
using System.Security;


namespace db
{  
   public class common
   {
         #region outScript(string str)  输出ALERT等script语句
        /// <summary>
        /// 生成js脚本字符串，可放到页面内
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string genScript(string str)
        {
            return ("<script language=javascript>" + str + "</script>");
        }
       #endregion
   

        public static System.Data.DataTable RunQuery(string sql)
        {
            return new db.DbHelper().RunQuery(sql);
        }


        #region 获取编号基数
        /// <summary>
        /// 获取编号基数
        /// </summary>
        /// <param name="name">类型ID,或表名，建议使用表名</param>
        /// <param name="isRootDB">是否是主数据库</param>
        /// <param name="len">编号长度</param>
        /// <param name="ia">分类号，即同一个数据表下的分类</param>
        /// <returns></returns>
        public static string getSeqId(string name, bool isRootDB, int len, string ia)
        {   //规则  先更新 加1，如果成功则直接查结果  应该改成存储过程
            string s = "";
          /*  if (RunNoQuery("update sys_seqid set code=(code+1) where name='" + name + "' and ia='" + ia + "'") <= 0)
            {
                RunNoQuery("update sys_seqid set code=(code+1) where name='sys_seqid' and ia='sys_seqid'");
                s = runASql("select code from sys_seqid where name='sys_seqid' and ia='sys_seqid'");

                RunNoQuery(string.Format("insert into sys_seqid(id,name,code,ia,ib)values('{0}','{1}','{2}','{3}','{4}')", s, name, 1, ia, 0));
            }
            s = runASql("select code from sys_seqid where name='" + name + "' and ia='" + ia + "'");//.Rows[0][0].ToString();
            for (int i = s.Length; i < len; i++) s = "0" + s;
            */
            return s;
        }

        #endregion
        #region "产生GUID"

        /// <summary>
        /// 获取一个GUID字符串
        /// </summary>
        public static string GetGUID
        {
            get
            {
                return Guid.NewGuid().ToString();
            }
        }
        #endregion
        #region "产生GUID"

        /// <summary>
        /// 获取一个GUID字符串
        /// </summary>
        public static string GetAID
        {
            get
            {
                string s = Guid.NewGuid().ToString();
                return s.Replace("-", "");
            }
        }
        #endregion


    }
}
